package m202405.d14;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/14 09:55
 */
public class Q78 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new LinkedList<>();
        for (int i = 0; i <= nums.length; i++) {
            List<List<Integer>> temp = new LinkedList<>();
            select(nums, i, temp, new HashSet<>());
            res.addAll(temp);
        }
        return res;
    }

    public void select(int[] nums, int count, List<List<Integer>> res, HashSet<Integer> set) {
        if (count == 0) {
            res.add(new LinkedList<>(set));
        }
        for (int i = 0; i < count; i++) {
            for (int num : nums) {
                if (set.contains(num)) {
                    continue;
                }
                set.add(num);
                select(nums, count - 1, res, set);
                set.remove(num);
            }
        }
    }
}
